import Foundation

struct Expense: Identifiable {
    let id: UUID
    let establishment: String
    let amount: Double
    let category: String
    let note: String
}

struct Budget: Identifiable {
    let id: UUID
    var category: String
    var limit: Double
    var expenses: [Expense]

    var spent: Double {
        expenses.reduce(0) { $0 + $1.amount }
    }

    static let sampleBudgets: [Budget] = [
    ]
}

struct SharedEntry: Identifiable {
    let id = UUID()
    let person: String
    let amountOwed: Double
    
    static let sampleSharedData = [
        SharedEntry(person: "Emma", amountOwed: 12),
        SharedEntry(person: "Jake", amountOwed: 8)
    ]
}

struct PersonSelection: Identifiable {
    let id = UUID()
    var name: String         // ← MUST be var
    var itemSelections: [UUID: Bool]
}

struct ExpenseItem: Identifiable, Codable, Hashable {
    let id: UUID
    let name: String
    let amount: Double

    init(id: UUID = UUID(), name: String, amount: Double) {
        self.id = id
        self.name = name
        self.amount = amount
    }

    enum CodingKeys: String, CodingKey {
        case name, amount
    }

    init(from decoder: Decoder) throws {
        let c = try decoder.container(keyedBy: CodingKeys.self)
        self.name = try c.decodeIfPresent(String.self, forKey: .name) ?? "Unknown"
        self.amount = try c.decodeIfPresent(Double.self, forKey: .amount) ?? 0
        self.id = UUID()
    }
}
